package com.jinunn.user.controller;

import com.atguigu.yygh.model.user.UserInfo;
import com.atguigu.yygh.vo.user.UserInfoQueryVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jinunn.common.result.Result;
import com.jinunn.user.service.UserInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author : JinDun
 * @date : 2021/5/20 10:23
 */

@RestController
@RequestMapping("admin/user")
public class UserController {

    @Autowired
    private UserInfoService userInfoService;

    @ApiOperation("用户列表（条件查询带分页）")
    @GetMapping("list/{page}/{limit}")
    public Result<Page<UserInfo>> getList(@PathVariable("page") Long page,
                                          @PathVariable("limit") Long limit,
                                          @RequestBody UserInfoQueryVo userInfoQueryVo){
        Page<UserInfo> list = userInfoService.getList(page,limit,userInfoQueryVo);
        return Result.ok(list);
    }

    @ApiOperation("用户锁定")
    @GetMapping("lock/{userId}/{status}")
    public Result<UserInfo> updateStatus(@PathVariable("userId") Integer userId,
                                         @PathVariable("status") Integer status){
       boolean result =  userInfoService.updateStatus(userId,status);
       if (result) {
           return Result.ok();
       }else {
           return Result.fail();
       }
    }

    @ApiOperation("根据用户id,获取用户信息和就诊人信息")
    @GetMapping("detail/{userId}")
    public Result<Map<String,Object>> detail(@PathVariable("userId") Integer userId){
        Map<String,Object> map  = userInfoService.getUserAndDictDetail(userId);
        return Result.ok(map);
    }

    @ApiOperation("修改认证状态")
    @GetMapping("approval/{userId}/{authStatue}")
    public Result<UserInfo> approvalAuthStatus(@PathVariable("userId") Integer userId,
                                               @PathVariable("authStatue") Integer authStatue){
        boolean result = userInfoService.approvalAuthStatus(userId,authStatue);
        return result ? Result.ok():Result.fail();
    }
}
